home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 70.5 KB | 2,649 lines | [TEXT/MPS ] |
- // UMacAppUtilities.cp
- // Copyright © 1984-1991 Apple Computer, Inc. All rights reserved.
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __STDIO__
- #include <StdIo.h>
- #endif
-
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
-
- #ifndef __SYSEQU__
- #include <SysEqu.h>
- #endif
-
- #ifndef __DEVICES__
- #include <Devices.h>
- #endif
-
- #ifndef __UGEOMETRY__
- #include <UGeometry.h>
- #endif
-
- #ifndef __ULOMEM__
- #include <ULoMem.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #ifndef __SANE__
- #include <SANE.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- // extern definitions:
- extern WindowPtr gWorkPort;
- extern const unsigned char kFrame;
-
- // constants
- const SignedByte initVal = 0xD3; // debugging constant, odd at all byte boundaries
-
- // Global variables defined so that storage is allocated:
- #if qDebug
- Boolean gPreCondition = TRUE;
- Boolean gPostCondition = TRUE;
- Boolean gAssumeFocused = TRUE; /* make TView.AssumeFocused actually check
- focus */
- Boolean gDebugPrinting = FALSE;
- Boolean gExperimenting = FALSE;
- Boolean gIntenseDebugging = FALSE;
- Boolean gReportEvt = FALSE;
- Boolean gReportMenuChoices = FALSE;
- short gRsrcCheck = kRsrcCheckInterval;
- Boolean gShowCursorRegion = FALSE;
- Boolean gShowHelpRegion = FALSE;
- Boolean gShowInvalidations = FALSE; /* make TWindow.InvalidVRect graphically show
- the invalidation region */
- Boolean gShowSleepRegion = FALSE;
- Boolean gTraceIdle;
- #endif
-
- const char* kCopyright = "MacApp® 3.0a2 Copyright © 1984-1991 Apple Computer, Inc. All rights reserved.";
- short gApplicationRefNum;
- ConfigRecord gConfiguration;
- BoolStrType gBoolString[2]; // = { "\pFALSE", "\pTRUE" };
-
- Boolean gToolBoxInitialized = FALSE;
- Boolean gUDialogInitialized = FALSE;
- Boolean gUGridViewInitialized = FALSE;
- Boolean gUPrintingInitialized = FALSE;
- Boolean gUTEViewInitialized = FALSE;
- Ptr gStrippedAddress = NULL;
-
- ProcPtr gFieldToStrRtn = NULL;
- ProcPtr gFieldToCountRtn = NULL;
-
- Boolean gDeadStripSuppression = FALSE;
- TEHandle gMATextBoxTE = NULL;
- WordBreakProcPtr gTEDefaultWordBreak = NULL;
- VHSelect gOrthogonal[2];
-
- Rect gZeroRect(0, 0, 0, 0);
- Point gZeroPt(0, 0);
- VPoint gZeroVPt(0, 0);
- VRect gZeroVRect(0, 0, 0, 0);
-
- RGBColor gRGBBlack;
- RGBColor gRGBWhite;
- RGBColor gRGBRed;
- RGBColor gRGBGreen;
- RGBColor gRGBBlue;
-
- // These are utilities. Treat them like language extensions.
- #pragma $W+
- #pragma $R-
- #pragma $Init-
- #pragma $OV-
- #if qNames
- #pragma $D+
- #endif
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- Boolean CWMgrIterator::More()
- {
- return (fCurrentWindow != NULL);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- void CWMgrIterator::Reset()
- {
- fCurrentWindow = GetWindowList();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- void CWMgrIterator::Advance()
- {
- if (fCurrentWindow)
- {
- fCurrentWindow = (WindowPtr)(((WindowPeek)fCurrentWindow)->nextWindow);
-
- while (fCurrentWindow && (fCurrentWindow == gWorkPort))
- // ignore the work window
- fCurrentWindow = (WindowPtr)(((WindowPeek)fCurrentWindow)->nextWindow);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean CanWriteLn(void)
-
- {
- #if qDebug
- return DebugCanWriteLn();
- #else
- return FALSE;
- #endif
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean CanReadLn(void)
-
- {
- #if qDebug
- return DebugCanReadLn();
- #else
- return FALSE;
- #endif
-
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean CompareMultiByteChars(const Str31& first,
- const Str31& second,
- Boolean caseSens)
- {
- short textOffset = 0;
- Boolean done = FALSE;
- Boolean areEqual;
- Str31 theChars = first; // point to first char in string (after length byte)
- Ptr theCharPtr = (Ptr) &theChars;
- theCharPtr++;
-
- do
- {
- short byteType = CharByte(theCharPtr, textOffset);// textOffset is zero-based
-
- ++textOffset;
- areEqual = first[textOffset] == second[textOffset];
- switch (byteType)
- {
- // special case single byte characters to allow lower case characters to map to
- // upper case characters
- case smSingleByte:
- if (caseSens)
- areEqual = (first[1] == second[1]);
- else
- areEqual = (LowerChar(first[1]) == LowerChar(second[1]));
- done = TRUE;
- break;
-
- case smFirstByte:
- done =!areEqual; // we're done if they don't match
- break;
-
- case smLastByte:
- done = TRUE;
- break;
-
- case smMiddleByte:
- done =!areEqual; // we're done if they don't match
- break;
- }
- } while (!done);
- return areEqual;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short CompareStrings(const Str255& first,
- const Str255& second)
-
- {
- return RelString(first, second, TRUE, TRUE);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void CopyStr255(const Str255& fmStr,
- Ptr toAddr)
- {
- Str255 copyString = fmStr;
-
- BlockMove((Ptr) ©String, toAddr, copyString.Length() + 1);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void DefaultSize(short& theSize)
-
- {
- if (theSize == GetDefFontSize())
- theSize = 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Handle DisposeIfHandle(Handle aHandle)
-
- {
-
- if (aHandle)
- {
- if (!qDebug)
- DisposHandle(aHandle);
- else
- {
- if (IsHandle(aHandle)) // Test handlehood
- {
- char handleBits = HGetState(aHandle);
- if (IsHandlePurged(aHandle)) // h might have been purged
- DisposHandle(aHandle);
- else if (MemError() != noErr)
- {
- fprintf(stderr, "Handle was so bad I couldn't even get the handle bits!\nBad Handle: %p\n", aHandle);
- ProgramBreak("");
- }
- else if (IsAResource(aHandle))
- {
- fprintf(stderr, "Trying to dispose a resource handle\nBad Handle: %p\n", aHandle);
- ProgramBreak("");
- }
- else
- {
- // Set the handle contents to a real nice value for any dangling pointerciples
- BlockSet((*aHandle), GetHandleSize(aHandle), initVal);
- DisposHandle(aHandle);
- }
- }
- else
- {
- VerboseIsHandle(aHandle); // Get the diagnosis printed
- fprintf(stderr, "Trying to dispose an invalid handle\nBad Handle: %p\n", aHandle);
- ProgramBreak("");
- }
- }
- }
-
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal PicHandle DisposeIfPicHandle(PicHandle aPicHandle)
-
- {
- if (aPicHandle)
- {
- if (!qDebug)
- KillPicture(aPicHandle);
- else
- {
- if (IsHandle((Handle)aPicHandle)) // Test handlehood
- {
- // Set the handle contents to a real nice value for any dangling pointerciples
- BlockSet(*((Handle)aPicHandle), GetHandleSize((Handle)aPicHandle), initVal);
- KillPicture(aPicHandle);
- }
- else
- {
- VerboseIsHandle((Handle)aPicHandle);// Get the diagnosis printed
- fprintf(stderr, "Trying to dispose an invalid PicHandle)\nBad PicHandle: %p\n", aPicHandle);
- ProgramBreak("");
- }
- }
- }
-
- return (PicHandle)NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Ptr DisposeIfPtr(Ptr aPtr)
-
- {
- if (aPtr)
- {
- if (!qDebug)
- DisposPtr(aPtr);
- else
- {
- // Test pointerhood, ??? Shouldn't we have a real test here?
- if (!((long)aPtr & 0x1))
- {
- BlockSet(aPtr, GetPtrSize(aPtr), initVal);
- DisposPtr(aPtr);
- }
- else
- {
- fprintf(stderr, "Trying to dispose an invalid pointer\nBad Pointer: %p\n", aPtr);
- ProgramBreak("");
- }
- }
- }
-
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal RgnHandle DisposeIfRgnHandle(RgnHandle aRgnHandle)
-
- {
- if (aRgnHandle)
- {
- if (!qDebug)
- DisposeRgn(aRgnHandle);
- else
- {
- // Test handlehood
- if (IsHandle((Handle)aRgnHandle))
- {
- // Set the handle contents to a real nice value for any dangling pointerciples
- BlockSet(*((Handle)aRgnHandle), GetHandleSize((Handle)aRgnHandle), initVal);
- DisposeRgn(aRgnHandle);
- }
- else
- {
- VerboseIsHandle((Handle)aRgnHandle);// Get the diagnosis printed
- fprintf(stderr, "Trying to dispose an invalid RgnHandle.\nBad RgnHandle: %p\n", aRgnHandle);
- ProgramBreak("");
- }
- }
- }
-
- return (RgnHandle)NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal SectionHandle DisposeIfSectionHandle(SectionHandle aSectionHandle)
-
- {
- if (aSectionHandle)
- {
- if (!qDebug)
- {
- DisposeIfHandle((Handle)(*aSectionHandle)->alias); // dispose of the alias
- DisposeIfHandle((Handle)aSectionHandle); // dispose of the SectionHandle
- }
- else
- {
- // Test handlehood
- if (IsHandle((Handle)aSectionHandle))
- {
- DisposeIfHandle((Handle)(*aSectionHandle)->alias); // dispose of the alias
-
- // Set the handle contents to a real nice value for any dangling pointerciples
- BlockSet(*((Handle)aSectionHandle), GetHandleSize((Handle)aSectionHandle), initVal);
- DisposeIfHandle((Handle)aSectionHandle); // dispose of the SectionHandle
- }
- else
- {
- VerboseIsHandle((Handle)aSectionHandle); // Get the diagnosis printed
- fprintf(stderr, "Trying to dispose an invalid SectionHandle.\nBad SectionHandle: %p\n", aSectionHandle);
- ProgramBreak("");
- }
- }
- }
-
- return (SectionHandle)NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void EachWMgrWindowDo(pascal void(* DoToWMgrWindow)(WindowPtr theWMgrWindow,
- void* staticLink),
- void* staticLink)
- {
- CWMgrIterator iter;
-
- for (WindowPtr aWindowPtr = iter.FirstWMgrWindow(); iter.More(); aWindowPtr = iter.NextWMgrWindow())
- DoToWMgrWindow(aWindowPtr, staticLink);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- // returns the window just before a given window. Returns NULL if the given window is frontmost
- // or not found.
- pascal WindowPtr FindWindowBefore(WindowPtr theWindow)
- {
- CWMgrIterator iter;
-
- for (WindowPtr theWMgrWindow = iter.FirstWMgrWindow(); iter.More(); theWMgrWindow = iter.NextWMgrWindow())
- if (((WindowPtr)((WindowPeek)theWMgrWindow)->nextWindow) == theWindow)
- return theWMgrWindow;
-
- return NULL;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short GetActualJustification(short justification)
-
- {
- if (justification == teFlushDefault)
- return GetSysJust();
- else
- return justification;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void GetDeskTopRegion(RgnHandle deskTopRgn)
-
- {
- if (qNeedsColorQD || gConfiguration.hasColorQD)// deskTopRgn = main screen rect
- RectRgn(deskTopRgn, (*GetMainDevice())->gdRect);
- else
- RectRgn(deskTopRgn, qd.screenBits.bounds);
- UnionRgn(GetGrayRgn(), deskTopRgn, deskTopRgn);// deskTopRgn = grayRgn + deskTopRgn
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short GetFontNum(const Str255& fontName)
-
- {
- short fontNum;
- Str255 localFontName(fontName);
-
- UprString(localFontName, FALSE);
- if (localFontName == kSysFontName)
- fontNum = GetSysFont();
- else if (localFontName == kApplFontName)
- fontNum = GetAppFont();
- else
- GetFNum(fontName, fontNum);
-
- return fontNum;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void GetIfBkColor(RGBColor& aColor)
-
- {
- const short BlackBit = 5;
- const short YellowBit = 6;
- const short MagentaBit = 7;
- const short CyanBit = 8;
-
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- GetBackColor(aColor);
- else
- { // Map old, dumb CMYB system to RGB color
- /* xxxxxxx C.MY B rgb w b == RGB
- blackColor == 33 == 0000000 0.00 1 000 0 1 == 000
- whiteColor == 30 == 0000000 0.00 0 111 1 0 == 111
- redColor == 205 == 0000000 0.11 0 011 0 1 == 100
- greenColor == 341 == 0000000 1.01 0 101 0 1 == 010
- blueColor == 409 == 0000000 1.10 0 110 0 1 == 001
- cyanColor == 273 == 0000000 1.00 0 100 0 1 == 011
- magentaColor == 137 == 0000000 0.10 0 010 0 1 == 101
- yellowColor == 69 == 0000000 0.01 0 001 0 1 == 110
- */
-
- long oldColor = qd.thePort->bkColor; // Fetch old color
- aColor = gRGBBlack; // Prime returned color to black
- if (oldColor & (0x1 << BlackBit)) // If color isn't black, force CMY == 111
- oldColor = (oldColor | 0x1C0);
- if (!(oldColor & (0x1 << CyanBit))) // Absence of cyan == presence of red
- aColor.red = 0xFFFF;
- if (!(oldColor & (0x1 << MagentaBit))) // Absence of magenta == presence of green
- aColor.green = 0xFFFF;
- if (!(oldColor & (0x1 << YellowBit))) // Absence of yellow == presence of blue
- aColor.blue = 0xFFFF;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void GetIfColor(RGBColor& aColor)
-
- {
- const short BlackBit = 5;
- const short YellowBit = 6;
- const short MagentaBit = 7;
- const short CyanBit = 8;
-
- if (qNeedsColorQD || gConfiguration.hasColorQD)
- GetForeColor(aColor);
- else
- { // Map old, dumb CMYB system to RGB color
- /* xxxxxxx C.MY B rgb w b == RGB
- blackColor == 33 == 0000000 0.00 1 000 0 1 == 000
- whiteColor == 30 == 0000000 0.00 0 111 1 0 == 111
- redColor == 205 == 0000000 0.11 0 011 0 1 == 100
- greenColor == 341 == 0000000 1.01 0 101 0 1 == 010
- blueColor == 409 == 0000000 1.10 0 110 0 1 == 001
- cyanColor == 273 == 0000000 1.00 0 100 0 1 == 011
- magentaColor == 137 == 0000000 0.10 0 010 0 1 == 101
- yellowColor == 69 == 0000000 0.01 0 001 0 1 == 110
- */
- long oldColor = qd.thePort->fgColor; // Fetch old color
- aColor = gRGBBlack; // Prime returned color to black
- if (oldColor & (0x1 << BlackBit)) /* If color isn't black, force CMY == 111 */
- oldColor = (oldColor | 0x1C0);
- if (!(oldColor & (0x1 << CyanBit))) // Absence of cyan == presence of red
- aColor.red = 0xFFFF;
- if (!(oldColor & (0x1 << MagentaBit))) // Absence of magenta == presence of green
- aColor.green = 0xFFFF;
- if (!(oldColor & (0x1 << YellowBit))) // Absence of yellow == presence of blue
- aColor.blue = 0xFFFF;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short MAGetFontInfo(FontInfo& theFontInfo)
- // MAGetFontInfo may be used in place of GetFontInfo since it also returns the font height.
-
- {
- GetFontInfo(theFontInfo); // get the current port's font info
- return (theFontInfo.ascent + theFontInfo.descent + theFontInfo.leading);// returns the font height
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void GetPortFontInfo(short fontNum,
- Str255& fontName,
- short& fontSize)
-
- {
- if ((fontNum == systemFont) || (fontNum == GetSysFont()))
- {
- fontName = kSysFontName;
- DefaultSize(fontSize);
- }
- else if ((fontNum == applFont) || (fontNum == GetAppFont()))
- {
- fontName = kApplFontName;
- DefaultSize(fontSize);
- }
- else
- GetFontName(fontNum, fontName);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment Main
-
- pascal SignedByte LockHandleHigh(Handle h)
-
- {
- SignedByte savedState = SignedByte(0);
- if (h)
- {
- if (qDebug &&!IsHandle(h))
- {
- VerboseIsHandle(h); // Get the diagnosis printed
- ProgramBreak("In LockHandleHigh: not handed a handle.");
- }
- else
- {
- savedState = HGetState(h);
- HLockHi(h); // ??? check MemErr ???
- }
- }
- return savedState;
- }
-
- //--------------------------------------------------------------------------------------------------
- // These should be inline functions but CFront outlined them. No way to stop it
- // because of the way MacApp uses them. (e.g. Max(Max(x, y) z); causes outlining )
-
- #pragma segment MAUtilitiesRes
-
- long Max(long a, long b)
- {
- return a > b ? a : b;
- }
-
- long Min(long a, long b)
- {
- return a < b ? a : b;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsFreeHandle(Handle aHandle)
- // Walk the free-list looking for the given handle
-
- {
- THz applZone = ApplicZone();
- Handle currHandle = (Handle)applZone->hFstFree;
-
- while (currHandle != NULL)
- {
- if (currHandle == aHandle)
- return TRUE;
- currHandle = (Handle) * currHandle;
- }
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsColorPort(GrafPtr port)
- /* Returns TRUE if the GrafPort is a Color QD GrafPort
- test is: IsColorPort = CGrafPtr(port)->portversion == 0xC000 */
-
- {
- if (port != NULL)
- return ((((CGrafPtr)port)->portVersion) & 0xC000) == 0x0000C000;
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsAResource(Handle h)
-
- {
- const short kResourceNotFound = -1;
- return HomeResFile(h) != kResourceNotFound;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsHandle(Handle h)
- // Returns true if handle appears valid.
-
- {
- if (h == NULL) // Test handle NULLness
- return FALSE; // handle is NULL
- else if (((long)h & 1) == 1) // Test handle Oddness
- return FALSE; // handle is odd (How odd!)
- else
- return (((long) * h & 1) == 0); // Test and return master pointer Oddness
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsHandleLocked(Handle h)
- // Returns lockState of h.
-
- {
- const short lockBit = 7;
-
- SignedByte handleBits = HGetState(h);
- if (MemError() == noErr) // h might have been purged
- return (handleBits & (0x1 << lockBit));
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #if qDebug
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsHandlePurged(Handle h)
- // Returns purgeState of h.
-
- {
- if (qDebug &&!IsHandle(h))
- {
- VerboseIsHandle(h); // Get the diagnosis printed
- ProgramBreak("IsHandlePurged was not handed a handle, pretty handy, eh?");
- return TRUE; /* !!! What is a decent result. shouldn't
- developer just signal failure from the
- debugger. We need to force the issue */
- }
- else
- return (*h == NULL);
- }
- #endif
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- static Boolean IsThisKeyDown(const short theKey)
- {
- union
- {
- KeyMap asMap;
- Byte asBytes[16];
- };
-
-
- GetKeys(asMap);
- return asBytes[theKey >> 3] & (1 << (theKey & 0x07)) ? true : false;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsCommandKeyDown(void)
-
- {
- const short kCommandKey = 55;
- return IsThisKeyDown(kCommandKey);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsControlKeyDown(void)
-
- {
- const short kCtlKey = 0x3B;
- return IsThisKeyDown(kCtlKey);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsOptionKeyDown(void)
-
- {
- const short kOptionKey = 58;
- return IsThisKeyDown(kOptionKey);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean IsShiftKeyDown(void)
-
- {
- const short kShiftKey = 56;
- return IsThisKeyDown(kShiftKey);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short GetWindowVariant(WindowPtr theWindow)
-
- {
- // For MacApp 3.0 app's, _GetWVariant is *always* available.
- return GetWVariant(theWindow);
-
- /*
- if (TrapExists(_GetWVariant))
- return GetWVariant(theWindow);
- else
- return BAND(0x0F, (((long) ((WindowPeek) theWindow)->windowDefProc) >> 24);
- */
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short LengthRect(const Rect& r,
- VHSelect vhs)
-
- {
- return r.Length(vhs);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal VHSelect LongerSide(Rect& r)
-
- {
- if ((r.Length(vSel)) >= (r.Length(hSel)))
- return vSel;
- else
- return hSel;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal VHSelect LongerVSide(VRect& r)
-
- {
- if ((r.Length(vSel)) >= (r.Length(hSel)))
- return vSel;
- else
- return hSel;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADebug
-
- pascal void LIntToHex(long decNumber,
- Str31& hexNumber,
- short noOfDigits)
-
- {
- short localNoOfDigits = (short)Min(noOfDigits, 8);
- long localDecNumber = decNumber;
- hexNumber[0] = (char)localNoOfDigits;
- for (short i = localNoOfDigits; i >= 1; i--, localDecNumber = localDecNumber >> 4)
- hexNumber[i] = kHexDigits[(localDecNumber & 15)];
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short LowerChar(short ch)
-
- {
- if ((ch >= 'A') && (ch <= 'Z'))
- return ch + 32;
- else
- return ch;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void LowerStr255(Str255& s)
-
- {
- for (short i = 1; i <= s.Length(); i++)
- if ((s[i] >= 'A') && (s[i] <= 'Z'))
- s[i] += 32;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short MAUseResFile(short refNum)
- // UseResFile the newResFile and return the old CurResFile.
-
- {
- short saveRefNum = CurResFile();
- UseResFile(refNum);
- return saveRefNum;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal long MinMax(long MinVal,
- long expression,
- long MaxVal)
- //Returns the bounded minimum and maximum
-
- {
- return Min(Max(expression, MinVal), MaxVal);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADebug
-
- pascal void NumberToHex(long theNumber,
- Str255& hexString,
- short hexDigits)
-
- {
- Str31 tempString;
-
- LIntToHex(theNumber, tempString, hexDigits);
- hexString = "$" + tempString;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADebug
-
- pascal void PointerToHex(long theNumber,
- Str255& hexString,
- short hexDigits)
-
- {
- Str31 tempString;
-
- if (theNumber == 0)
- hexString = "NULL";
- else
- {
- LIntToHex(theNumber, tempString, hexDigits);
- hexString = "$" + tempString;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFile
-
- pascal long NumBlocks(long numBytes,
- long blkSize)
-
- {
- return (numBytes + blkSize - 1) / blkSize;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- Handle pSaveHText;
- Handle pMATextBoxHText = NULL;
-
- pascal void StdNoRect(GrafVerb verb,
- const Rect* r)
- // StdNoRect filters out the rect drawing calls.
-
- {
- }
-
-
- void InitMyPrivateTE(const Rect& box,
- short heapSize)
-
- {
- const short kZoneHeader = 52; // 52 bytes for header
- const short kZoneTrailer = 12; // 12 bytes for trailer
- const short kMPBlockHeader = 8; // 8 bytes for Master Pointer block hdr
- const short kInitialMstrPtrs = 2; // 2 master pointers created initially
- const short kSlop = 20; // bytes of slop (just in case)
- const short kZoneOverhead = kZoneHeader + kZoneTrailer + kMPBlockHeader + 4 * kInitialMstrPtrs + kSlop;// how large the zone overhead is
- Ptr aTEZonePtr;
-
- gMATextBoxTE = TENew(box, box);
- if (gMATextBoxTE == NULL) // can't allocate space for our terecord
- return;
-
- // • save off several items of interest
- gTEDefaultWordBreak = (*gMATextBoxTE)->wordBreak;
- pSaveHText = (*gMATextBoxTE)->hText; // save the text handle
-
- /* • Since TESetText (called near the end of MATextBox) hits the heap, we can speed this hit
- to the heap for small text lengths (<= 255), by allocating a special text handle in its own
- separate heap. We'll use this text handle whenever the text length is <= 255. */
-
- /* • create a separate heap */
- aTEZonePtr = NewPtr(heapSize + kZoneOverhead);
- if (aTEZonePtr == NULL) // can't allocate space for our heap
- return;
- InitZone(NULL, kInitialMstrPtrs, aTEZonePtr + GetPtrSize(aTEZonePtr), aTEZonePtr);
-
- /* • InitZone sets the current zone to the newly created zone */
-
- /* • allocate our new text handle in our new heap zone */
- pMATextBoxHText = NewHandle(heapSize); // the text handle
-
- /* • restore the heap zone */
- SetZone(ApplicZone());
- }
-
-
- pascal void MATextBox(Ptr text,
- long itsLength,
- const Rect& box,
- short itsJust,
- Boolean autoWrap,
- ProcPtr wordBreak,
- Boolean eraseFirst,
- Boolean spaceForCaret)
-
- {
-
- const short kTextBoxCaretSlopSize = 1; /* Since TextBox uses TE to image the text,
- we may need to adjust by 1 pixel. Reason:
- TE draws beginning 1 pixel to the right to
- allow for the insertion point (which we
- won't have since this is drawn text, not
- editable text).*/
- const short kMaxTEChars = 32000; /* Actually TE suffers some other limitations
- as well. Such as misbehaviour and or
- bombing when the sum of the lineheights >
- 32k or a linewidth > 32k (overflows
- QuickDraw space) But these are _MUCH_ more
- difficult to test for in a quick way */
- const short kOurHeapSize = 255; // our zone size
-
- FontInfo fInfo;
- /* these next two locals eat up lots of stack space...this could be improved by allocating
- a pointer for the one that is used (eg allocate a pointer for myCQDProcs if CDQ available) */
- QDProcs myQDProcs;
- CQDProcs myCQDProcs;
- QDProcsPtr saveQDProcsPtr;
- Ptr saveRectProc;
- // Create my goodies if necessary
- if (gMATextBoxTE == NULL)
- {
- InitMyPrivateTE(box, kOurHeapSize);
-
- if (gMATextBoxTE == NULL) // couldn't allocate the TE handle
- {
- TextBox(text, itsLength, box, itsJust);// default to TextBox in low memory
- return;
- }
- }
-
- // Setup the work TE with the necessary parameters
- GetFontInfo(fInfo); // Need to get font's height and ascent.
-
- (SectRect((*(qd.thePort->clipRgn))->rgnBBox, box, (*gMATextBoxTE)->viewRect));
- (*gMATextBoxTE)->destRect = box;
- if (!spaceForCaret) /* widen the destrect but not the visrect.
- This lets the 1 pixel wide area to the
- left of all text and the right of all text
- go unshown. */
- {
- (*gMATextBoxTE)->destRect.left = (*gMATextBoxTE)->destRect.left - kTextBoxCaretSlopSize;
- (*gMATextBoxTE)->destRect.right = (*gMATextBoxTE)->destRect.right + kTextBoxCaretSlopSize;
- }
-
- (*gMATextBoxTE)->inPort = qd.thePort; // Current port and its characteristics
-
- (*gMATextBoxTE)->txSize = qd.thePort->txSize;
- (*gMATextBoxTE)->txFont = qd.thePort->txFont;
- (*gMATextBoxTE)->txFace = qd.thePort->txFace;
- (*gMATextBoxTE)->fontAscent = fInfo.ascent;
- (*gMATextBoxTE)->lineHeight = fInfo.ascent + fInfo.descent + fInfo.leading;
- (*gMATextBoxTE)->just = itsJust;
-
- if (autoWrap)
- (*gMATextBoxTE)->crOnly = 0; //if >=0, word wrap
- else
- (*gMATextBoxTE)->crOnly = -1; //if <0, new line at Return only
-
- (*gMATextBoxTE)->wordBreak = gTEDefaultWordBreak;
-
- if (wordBreak != NULL)
- SetWordBreak((WordBreakProcPtr)wordBreak, gMATextBoxTE);// set the word break routine
-
- if (pMATextBoxHText != NULL) // if our private heap is set up
- {
- if (itsLength > kOurHeapSize)
- (*gMATextBoxTE)->hText = pSaveHText;
- else
- (*gMATextBoxTE)->hText = pMATextBoxHText;
- }
-
- TESetText(text, Min(itsLength, kMaxTEChars), gMATextBoxTE);
-
- // if called with eraseFirst TRUE, then let TEUpdate image with its built-in EraseRect
- if (eraseFirst)
- TEUpdate(box, gMATextBoxTE);
- else
- {
- /* replace the existing QD procs ( standard or externally supplied )
- so that the EraseRect in TEUpdate is ignored */
- saveQDProcsPtr = qd.thePort->grafProcs;
-
- if (saveQDProcsPtr == NULL)
- {
- if (IsColorPort(qd.thePort))
- {
- SetStdCProcs(myCQDProcs);
- myCQDProcs.rectProc = (Ptr) & StdNoRect;
- qd.thePort->grafProcs = (QDProcsPtr) & myCQDProcs;
- }
- else
- {
- SetStdProcs(myQDProcs);
- myQDProcs.rectProc = (Ptr) & StdNoRect;
- qd.thePort->grafProcs = &myQDProcs;
- }
- }
- else
- {
- saveRectProc = qd.thePort->grafProcs->rectProc;
- qd.thePort->grafProcs->rectProc = (Ptr) & StdNoRect;
- }
-
- // Now do the imaging
- TEUpdate(box, gMATextBoxTE);
-
- // Restore the QDProcs
- if (saveQDProcsPtr == NULL)
- qd.thePort->grafProcs = NULL;
- else
- qd.thePort->grafProcs->rectProc = saveRectProc;
-
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void MADrawString(const Str255& s,
- const Rect& box,
- short justification)
-
- {
- FontInfo theFontInfo;
- short widthOfString;
- short boxWidth;
- Rect localBox = box;
-
- GetFontInfo(theFontInfo);
- widthOfString = StringWidth(s);
- boxWidth = localBox.Length(hSel);
- if (widthOfString < boxWidth)
- {
- switch (GetActualJustification(justification))
- {
- case teFlushDefault:
- break;
-
- case teCenter:
- localBox.left += (boxWidth - widthOfString) / 2;
- break;
-
- case teFlushRight:
- localBox.left += boxWidth - widthOfString;
- break;
-
- case teFlushLeft:
- break;
- }
- }
-
- MoveTo(localBox.left, localBox.top + theFontInfo.ascent);
- DrawString(s);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal long PinOnRect(const Rect& theRect,
- Point thePt)
-
- {
- Point localPt = thePt;
- if (localPt.h < theRect.left)
- localPt.h = theRect.left;
- if (localPt.h > theRect.right)
- localPt.h = theRect.right;
- if (localPt.v < theRect.top)
- localPt.v = theRect.top;
- if (localPt.v > theRect.bottom)
- localPt.v = theRect.bottom;
-
- return (localPt.v << sizeof(short)) + localPt.h;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void PinOnVRect(const VRect& theRect,
- const VPoint& thePt,
- VPoint& thePin)
-
- {
- thePin = VPoint(MinMax(theRect.top, thePt.h, theRect.bottom), MinMax(theRect.left, thePt.h, theRect.right));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal short ReadInteger(const Str255& prompt)
-
- {
- short i;
-
- #if qDebug
- DebugForceOutput(forceOn, forceUnchanged);
- #endif
-
- fprintf(stderr, "%s", (char*)prompt);
- fscanf(stdin, "%d", &i);
- #if qDebug
- DebugEndForce();
- #endif
-
- return i;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal Boolean ReadYesNo(const Str255& prompt)
-
- {
- char userInput[10] = "";
-
- #if qDebug
- DebugForceOutput(forceOn, forceUnchanged);
- #endif
-
- fprintf(stderr, "%s", (char*)prompt);
- fscanf(stdin, "%s", userInput);
- #if qDebug
- DebugEndForce();
- #endif
-
- return ((userInput != "") && ((userInput[0] == 'y') || (userInput[0] == 'Y')));
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean RectsNest(const Rect& outer,
- const Rect& inner)
-
- {
- return outer.Contains(inner);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal Boolean VRectsNest(const VRect& outer,
- const VRect& inner)
-
- {
- return outer.Contains(inner);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal long RoundUp(long aNumber,
- short aModulus)
-
- {
- return ((aNumber + aModulus - 1) / aModulus) * aModulus;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short SetKeyScript(short newKeyScript)
-
- {
- short currentKeyScript = (short)GetEnvirons(smKeyScript);
- if (currentKeyScript != newKeyScript) // Don't unnecessarily annoy the script mgr
- KeyScript(newKeyScript);
- return currentKeyScript;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void SetIfBkColor(const RGBColor& aColor)
-
- {
- const short SignBit = 15;
-
- if ((qNeedsColorQD || gConfiguration.hasColorQD) && IsColorPort(qd.thePort))
- {
- RGBColor tmpColor = aColor;
-
- // if color doesn't match then make trap
- if (!EqualBlocks((Ptr) & ((CGrafPtr)qd.thePort)->rgbBkColor, (Ptr) &tmpColor, sizeof(RGBColor)))
- RGBBackColor(aColor);
- }
- else
- {
- short index = 0; // Prime index
- long oldColor;
- if (aColor.red & (0x1 << SignBit)) // Set bit if red >= 0x8000
- index = 4;
- if (aColor.green & (0x1 << SignBit)) // Set bit if green >= 0x8000
- index = index + 2;
- if (aColor.blue & (0x1 << SignBit)) // Set bit if blue >= 0x8000
- ++index;
- switch (index)
- {
- case 0:
- oldColor = blackColor;
- break;
-
- case 1:
- oldColor = blueColor;
- break;
-
- case 2:
- oldColor = greenColor;
- break;
-
- case 3:
- oldColor = cyanColor;
- break;
-
- case 4:
- oldColor = redColor;
- break;
-
- case 5:
- oldColor = magentaColor;
- break;
-
- case 6:
- oldColor = yellowColor;
- break;
-
- case 7:
- oldColor = whiteColor;
- break;
-
- }
- BackColor(oldColor);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void SetIfColor(const RGBColor& aColor)
-
- {
- const short SignBit = 15;
-
- if ((qNeedsColorQD || gConfiguration.hasColorQD) && IsColorPort(qd.thePort))
- {
- RGBColor tmpColor = aColor;
-
- // if color doesn't match then make trap
- if (!EqualBlocks((Ptr) & ((CGrafPtr)qd.thePort)->rgbFgColor, (Ptr) &tmpColor, sizeof(RGBColor)))
- RGBForeColor(aColor);
- }
- else
- {
- short index = 0; // Prime index
- long oldColor;
-
- if (aColor.red & (0x1 << SignBit)) // Set bit if red >= 0x8000
- index = 4;
- if (aColor.green & (0x1 << SignBit)) // Set bit if green >= 0x8000
- index = index + 2;
- if (aColor.blue & (0x1 << SignBit)) // Set bit if blue >= 0x8000
- ++index;
- switch (index)
- {
- case 0:
- oldColor = blackColor;
- break;
-
- case 1:
- oldColor = blueColor;
- break;
-
- case 2:
- oldColor = greenColor;
- break;
-
- case 3:
- oldColor = cyanColor;
- break;
-
- case 4:
- oldColor = redColor;
- break;
-
- case 5:
- oldColor = magentaColor;
- break;
-
- case 6:
- oldColor = yellowColor;
- break;
-
- case 7:
- oldColor = whiteColor;
- break;
- }
- ForeColor(oldColor);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void GetPortTextStyle(TextStyle& theTextStyle)
-
- {
- theTextStyle.tsFont = qd.thePort->txFont;
- theTextStyle.tsFace = qd.thePort->txFace;
- theTextStyle.tsSize = qd.thePort->txSize;
- GetIfColor(theTextStyle.tsColor);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void SetPortTextStyle(const TextStyle& theTextStyle)
-
- {
- if (qd.thePort->txFont != theTextStyle.tsFont)
- TextFont(theTextStyle.tsFont);
- if (qd.thePort->txFace != theTextStyle.tsFace)
- TextFace(theTextStyle.tsFace);
- if (qd.thePort->txSize != theTextStyle.tsSize)
- TextSize(theTextStyle.tsSize);
- SetIfColor(theTextStyle.tsColor);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void SetTextStyle(TextStyle& theTextStyle,
- short theFont,
- /* Style */
- short theStyle,
- short theSize,
- const RGBColor& theColor)
-
- {
- theTextStyle.tsFont = theFont;
- theTextStyle.tsFace = theStyle;
- theTextStyle.tsSize = theSize;
- theTextStyle.tsColor = theColor;
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal void StdFieldToCount(short& count,
- short fieldType)
-
- {
- switch (fieldType)
- {
- case bTextStyle:
- count = count + kTextStyleFields;
- break;
-
- case bQDProcs:
- count = count + kQDProcsFields;
- break;
-
- case bCQDProcs:
- count = count + kCQDProcsFields;
- break;
-
- case bScrapStuff:
- count = count + kScrapStuffFields;
- break;
-
- case bConfigRec:
- count = count + kConfigRecFields;
- break;
-
- case bSectionRecord:
- count = count + kSectionRecordFields;
- break;
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal short UprChar(short ch)
-
- {
- if ((ch >= 'a') && (ch <= 'z'))
- return ch - 32;
- else
- return ch;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void UprStr255(Str255& s)
-
- {
- for (short i = 1; i <= s.Length(); i++)
- if ((s[i] >= 'a') && (s[i] <= 'z'))
- s[i] = s[i] - 32;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void UprMAName(MAName& s)
-
- {
- for (short i = 1; i <= s.Length(); i++)
- if ((s[i] >= 'a') && (s[i] <= 'z'))
- s[i] = s[i] - 32;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void UseROMMap(Boolean resLoad)
-
- {
- if (resLoad)
- (*GetROMMapInsert()) = kLMmapTrue;
- else
- (*GetROMMapInsert()) = kLMmapFalse;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void UseSelectionColor(void)
-
- {
- BitClr((Ptr)HiliteMode, 0);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADebug
-
- pascal Boolean VerboseIsHandle(Handle h)
-
- {
- const long kUnInitStorage1 = 0x72677267; // Pascal provided uninited storage
- const long kUnInitStorage2 = 0x67726772; // odd byte boundary of above
- const long kDebugHandleInit = 0xF3F3F3F3; // Handles are inited to this in MacApp®
- const long kDebugPtrInit = 0xF5F5F5F5; // Pointers are inited to this in MacApp®
- const long kDebugObjInit = 0xF1F1F1F1; // Objects are inited to this in MacApp®
-
- if (((long)h & 1) != 0)
- {
- if ((long)h == kUnInitStorage1)
- fprintf(stderr, " That handle appears to be from uninitialized storage.");
- else if ((long)h == kDebugHandleInit)
- fprintf(stderr, " That handle appears to be from a handle initialized by debugging.");
- else if ((long)h == kDebugPtrInit)
- fprintf(stderr, " That handle appears to be from a pointer initialized by debugging.");
- else if ((long)h == kDebugObjInit)
- fprintf(stderr, " That handle appears to be an uninitialized instance variable.");
- else
- fprintf(stderr, " That handle is odd.");
- }
- else if ((long)h == kUnInitStorage2)
- fprintf(stderr, " That handle appears to be from uninitialized storage.");
- else if (h == NULL)
- fprintf(stderr, " That handle is NULL.");
- else
- {
- Ptr masterPointer = (*h);
- if (((long)masterPointer & 1) != 0)
- fprintf(stderr, " The master pointer is odd.");
- else if (IsFreeHandle(h))
- fprintf(stderr, " The handle has been freed.");
- else
- return TRUE;
- }
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- pascal void WithApplicationResFileDo(pascal void(* DoWithResFile)(void* staticLink),
- void* staticLink)
- //??? Needs a failure handler ???
-
- {
- short oldResFile = CurResFile();
- UseResFile(gApplicationRefNum);
- DoWithResFile(staticLink);
- UseResFile(oldResFile);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WriteHandleContents(Handle theHandle)
-
- {
- Size Max = GetHandleSize(theHandle) - 1;
- if (Max > 0)
- {
- Boolean wasLocked = IsHandleLocked(theHandle);
- if (!wasLocked)
- HLock(theHandle);
- for (short index = 0; index <= Max; index++)
- fprintf(stderr, "%x", *((Ptr)(*theHandle + index)));
- if (!wasLocked)
- HUnlock(theHandle);
- }
- else
- fprintf(stderr, "**Empty**");
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblHandleContents(const Str255& aLabel,
- Handle theHandle)
-
- {
- fprintf(stderr, "%s = ", (char*)aLabel);
- WriteHandleContents(theHandle);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void ItsCallBack(const Str255& ,
- const Str255& theString,
- void* ,
- short,
- void*)
-
- {
- fprintf(stderr, "%s", (char*)theString);
- }
-
-
- pascal void WriteField(Ptr fieldAddr,
- short fieldType)
-
- {
- short foo;
- FieldToString("", fieldAddr, fieldType, ItsCallBack, &foo);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WritePt(Point pt)
-
- {
- WriteField((Ptr) & pt, bPoint);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblPt(const Str255& aLabel,
- Point pt)
-
- {
- fprintf(stderr, "%s = ", (char*)aLabel);
- WritePt(pt);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WritePtr(long val)
-
- {
- WriteField((Ptr) & val, bPointer);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblPtr(const Str255& aLabel,
- long val)
-
- {
- fprintf(stderr, "%s = ", (char*)aLabel);
- WritePtr(val);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WriteRect(const Rect& r)
- {
- Rect tmpRect = r;
-
- WriteField((Ptr) &tmpRect, bRect);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblRect(const Str255& aLabel,
- const Rect& r)
-
- {
- fprintf(stderr, "%s = ", (char*)aLabel);
- WriteRect(r);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WriteBoolean(Boolean b)
-
- {
- WriteField((Ptr) & b, bBoolean);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblBoolean(const Str255& aLabel,
- Boolean b)
-
- {
- fprintf(stderr, "%s = ", (char*)aLabel);
- WriteBoolean(b);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WriteVPt(const VPoint& pt)
- {
- VPoint tmpPoint = pt;
-
- WriteField((Ptr) &tmpPoint, bVPoint);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblVPt(const Str255& aLabel,
- const VPoint& pt)
-
- {
- fprintf(stderr, "%s = ", (char*)aLabel);
- WriteVPt(pt);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WriteVRect(const VRect& r)
- {
- VRect tmpRect = r;
-
- WriteField((Ptr) &tmpRect, bVRect);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblVRect(const Str255& aLabel,
- const VRect& r)
-
- {
- fprintf(stderr, "%s = ", (char*)aLabel);
- WriteVRect(r);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WriteSig(IDType theID)
-
- {
- WriteField((Ptr) & theID, bIDType);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblSig(const Str255& theLabel,
- IDType theID)
-
- {
- fprintf(stderr, "%s = ", (char*)theLabel);
- WriteSig(theID);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WriteHexInt(short theInt)
-
- {
- WriteField((Ptr) & theInt, bHexInteger);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblHexInt(const Str255& theLabel,
- short theInt)
-
- {
- fprintf(stderr, "%s = ", (char*)theLabel);
- WriteHexInt(theInt);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WriteHexLongint(long theLongint)
-
- {
- WriteField((Ptr) & theLongint, bHexLongInt);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment WWSeg
-
- pascal void WrLblHexLongint(const Str255& theLabel,
- long theLongint)
-
- {
- fprintf(stderr, "%s = ", (char*)theLabel);
- WriteHexLongint(theLongint);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MADebug2
-
- void CheckAdornment(CntlAdornment p,
- CntlAdornment alias,
- Str255 theString,
- char* name)
-
- {
- // "set1 <= set2" means set1 is wholly contained in set2
- if (p <= alias)
- if (theString == Str255("["))
- theString = theString + name;
- else
- theString = theString + Str255(",") + name;
- }
-
-
- void CheckStyleItem(unsigned char s,
- unsigned char alias,
- Str255 theString,
- char* name)
-
- {
- if (s & alias)
- if (theString == Str255("["))
- theString = theString + name;
- else
- theString = theString + Str255(",") + name;
- }
-
-
- void DoScrapStuff(const Str255& fieldLabel,
- ScrapStuff* theScrapStuff,
- pascal void(* ProcessField)(const Str255& theLabel,
- const Str255& theString,
- void* theData,
- short theType,
- void* staticLink),
- void* staticLink)
-
- {
- Str255 aString = "";
- FieldToString(fieldLabel, NULL, bTitle, ProcessField, staticLink);
- FieldToString(" scrapSize", &theScrapStuff->scrapSize, bLongInt, ProcessField, staticLink);
- FieldToString(" scrapHandle", &theScrapStuff->scrapHandle, bHandle, ProcessField, staticLink);
- FieldToString(" scrapCount", &theScrapStuff->scrapCount, bInteger, ProcessField, staticLink);
- FieldToString(" scrapState", &theScrapStuff->scrapState, bInteger, ProcessField, staticLink);
- if (theScrapStuff->scrapName != NULL)
- FieldToString(" scrapName", &theScrapStuff->scrapName, bString, ProcessField, staticLink);
- else
- FieldToString(" scrapName", NULL, bPointer, ProcessField, staticLink);
- }
-
-
- void DoConfigRecord(const Str255& fieldLabel,
- ConfigRecord* theConfigRecord,
- pascal void(* ProcessField)(const Str255& theLabel,
- const Str255& theString,
- void* theData,
- short theType,
- void* staticLink),
- void* staticLink)
-
- {
- Str255 aString = "";
- FieldToString(fieldLabel, NULL, bTitle, ProcessField, staticLink);
- FieldToString(" gestaltVersion", &theConfigRecord->environsVersion, bInteger, ProcessField, staticLink);
-
- switch (theConfigRecord->machineType)
- {
- case gestaltClassic:
- aString = "gestaltClassic";
- break;
-
- case gestaltMacXL:
- aString = "gestaltMacXL";
- break;
-
- case gestaltMac512KE:
- aString = "gestaltMac512KE";
- break;
-
- case gestaltMacPlus:
- aString = "gestaltMacPlus";
- break;
-
- case gestaltMacSE:
- aString = "gestaltMacSE";
- break;
-
- case gestaltMacII:
- aString = "gestaltMacII";
- break;
-
- case gestaltMacIIx:
- aString = "gestaltMacIIx";
- break;
-
- case gestaltMacIIcx:
- aString = "gestaltMacIIcx";
- break;
-
- case gestaltMacSE030:
- aString = "gestaltMacSE030";
- break;
-
- case gestaltPortable:
- aString = "gestaltPortable";
- break;
-
- case gestaltMacIIci:
- aString = "gestaltMacIIci";
- break;
-
- default:
- aString = "gestaltMachUnknown";
- break;
- }
-
- FieldToString(" machineType", &aString, bString, ProcessField, staticLink);
-
- FieldToString(" systemVersion", &theConfigRecord->systemVersion, bHexInteger, ProcessField, staticLink);
-
- switch (theConfigRecord->processor)
- {
- case gestalt68000:
- aString = "gestalt68000";
- break;
-
- case gestalt68010:
- aString = "gestalt68010";
- break;
-
- case gestalt68020:
- aString = "gestalt68020";
- break;
-
- case gestalt68030:
- aString = "gestalt68030";
- break;
-
- case gestalt68040:
- aString = "gestalt68040";
- break;
-
- default:
- aString = "gestaltCPUUnknown";
- break;
- }
- FieldToString(" processor", &aString, bString, ProcessField, staticLink);
-
- FieldToString(" hasFPU", &theConfigRecord->hasFPU, bBoolean, ProcessField, staticLink);
- FieldToString(" hasColorQD", &theConfigRecord->hasColorQD, bBoolean, ProcessField, staticLink);
-
- switch (theConfigRecord->keyboardType)
- {
- case gestaltMacKbd:
- aString = "gestaltMacKbd";
- break;
-
- case gestaltMacAndPad:
- aString = "gestaltMacAndPad";
- break;
-
- case gestaltMacPlusKbd:
- aString = "gestaltMacPlusKbd";
- break;
-
- case gestaltExtADBKbd:
- aString = "gestaltExtADBKbd";
- break;
-
- case gestaltStdADBKbd:
- aString = "gestaltStdADBKbd";
- break;
-
- case gestaltPrtblADBKbd:
- aString = "gestaltPrtblADBKbd";
- break;
-
- case gestaltPrtblISOKbd:
- aString = "gestaltPrtblISOKbd";
- break;
-
- case gestaltStdISOADBKbd:
- aString = "gestaltStdISOADBKbd";
- break;
-
- case gestaltExtISOADBKbd:
- aString = "gestaltExtISOADBKbd";
- break;
-
- case gestaltADBKbdII:
- aString = "gestaltADBKbdII";
- break;
-
- case gestaltADBISOKbdII:
- aString = "gestaltADBISOKbdII";
- break;
-
- default:
- aString = "gestaltUnknownKbd";
- break;
- }
- FieldToString(" keyboardType", &aString, bString, ProcessField, staticLink);
-
- FieldToString(" atDrvrVersNum", &theConfigRecord->atDrvrVersNum, bInteger, ProcessField, staticLink);
- FieldToString(" sysVRefNum", &theConfigRecord->sysVRefNum, bInteger, ProcessField, staticLink);
-
- switch (theConfigRecord->teVersion)
- {
- case gestaltTE1:
- aString = "gestaltTE1";
- break;
-
- case gestaltTE2:
- aString = "gestaltTE2";
- break;
-
- case gestaltTE3:
- aString = "gestaltTE3";
- break;
-
- case gestaltTE4:
- aString = "gestaltTE4";
- break;
-
- default:
- aString = "gestaltUnknownTE";
- break;
- }
- FieldToString(" teVersion", &aString, bString, ProcessField, staticLink);
-
- FieldToString(" hasROM128K", &theConfigRecord->hasROM128K, bBoolean, ProcessField, staticLink);
- FieldToString(" hasHFS", &theConfigRecord->hasHFS, bBoolean, ProcessField, staticLink);
- FieldToString(" hasHierarchicalMenus", &theConfigRecord->hasHierarchicalMenus, bBoolean, ProcessField, staticLink);
- FieldToString(" hasScriptManager", &theConfigRecord->hasScriptManager, bBoolean, ProcessField, staticLink);
- FieldToString(" hasStyleTextEdit", &theConfigRecord->hasStyleTextEdit, bBoolean, ProcessField, staticLink);
- FieldToString(" hasSoundManager", &theConfigRecord->hasSoundManager, bBoolean, ProcessField, staticLink);
- FieldToString(" hasWaitNextEvent", &theConfigRecord->hasWaitNextEvent, bBoolean, ProcessField, staticLink);
- FieldToString(" hasSCSI", &theConfigRecord->hasSCSI, bBoolean, ProcessField, staticLink);
- FieldToString(" hasDesktopBus", &theConfigRecord->hasDesktopBus, bBoolean, ProcessField, staticLink);
- FieldToString(" hasAUX", &theConfigRecord->hasAUX, bBoolean, ProcessField, staticLink);
- FieldToString(" hasTempMem", &theConfigRecord->hasTempMem, bBoolean, ProcessField, staticLink);
- FieldToString(" has32BitQD", &theConfigRecord->has32BitQD, bBoolean, ProcessField, staticLink);
- FieldToString(" hasAppleEventMgr", &theConfigRecord->hasAppleEventMgr, bBoolean, ProcessField, staticLink);
- FieldToString(" hasEditionMgr", &theConfigRecord->hasEditionMgr, bBoolean, ProcessField, staticLink);
- FieldToString(" hasHelpMgr", &theConfigRecord->hasHelpMgr, bBoolean, ProcessField, staticLink);
- FieldToString(" hasAliasMgr", &theConfigRecord->hasAliasMgr, bBoolean, ProcessField, staticLink);
- FieldToString(" hasFolderMgr", &theConfigRecord->hasFolderMgr, bBoolean, ProcessField, staticLink);
- FieldToString(" hasProcessMgr", &theConfigRecord->hasProcessMgr, bBoolean, ProcessField, staticLink);
- FieldToString(" hasPopupCDEF", &theConfigRecord->hasPopupCDEF, bBoolean, ProcessField, staticLink);
- }
-
-
- void DoSectionRecord(const Str255& fieldLabel,
- SectionRecord* theSectionRecord,
- pascal void(* ProcessField)(const Str255& theLabel,
- const Str255& theString,
- void* theData,
- short theType,
- void* staticLink),
- void* staticLink)
- {
- Str255 aString = "";
- FieldToString(fieldLabel, NULL, bTitle, ProcessField, staticLink);
- FieldToString(" version", &theSectionRecord->version, bByte, ProcessField, staticLink);
-
- if (theSectionRecord->kind == stPublisher)
- aString = "publisher";
- else if (theSectionRecord->kind == stSubscriber)
- aString = "subscriber";
- else
- aString = "unknown";
- FieldToString(" kind", &aString, bString, ProcessField, staticLink);
-
- FieldToString(" mode", &theSectionRecord->mode, bInteger, ProcessField, staticLink);
- FieldToString(" mdDate", &theSectionRecord->mdDate, bLongInt, ProcessField, staticLink);
- FieldToString(" sectionID", &theSectionRecord->sectionID, bLongInt, ProcessField, staticLink);
- FieldToString(" refCon", &theSectionRecord->refCon, bLongInt, ProcessField, staticLink);
- FieldToString(" alias", &theSectionRecord->alias, bHandle, ProcessField, staticLink);
- FieldToString(" subPart", &theSectionRecord->subPart, bLongInt, ProcessField, staticLink);
- FieldToString(" nextSection", &theSectionRecord->nextSection, bHandle, ProcessField, staticLink);
- FieldToString(" controlBlock", &theSectionRecord->controlBlock, bHandle, ProcessField, staticLink);
- FieldToString(" refNum", &theSectionRecord->refNum, bHandle, ProcessField, staticLink);
- }
-
-
- pascal void StdFieldToString(const Str255& fieldLabel,
- void* theData,
- short fieldType,
- pascal void(* ProcessField)(const Str255& theLabel,
- const Str255& theString,
- void* theData,
- short theType,
- void* staticLink),
- void* staticLink)
-
- {
- const short kDecPrec = 4; // decimal precision in extended
-
- Str255 aString = "";
- Str255 theString = "";
- // Extended support
-
- switch (fieldType)
- {
- case bTextStyle:
- {
- FieldToString(fieldLabel, NULL, bTitle, ProcessField, staticLink);
- FieldToString(" Font", &((TextStyle *)theData)->tsFont, bFontName, ProcessField, staticLink);
- FieldToString(" Face", &((TextStyle *)theData)->tsFace, bStyle, ProcessField, staticLink);
- FieldToString(" Size", &((TextStyle *)theData)->tsSize, bInteger, ProcessField, staticLink);
- FieldToString(" Color", &((TextStyle *)theData)->tsColor, bRGBColor, ProcessField, staticLink);
- break;
- }
-
- case bQDProcs:
- {
- FieldToString(fieldLabel, NULL, bTitle, ProcessField, staticLink);
- FieldToString(" textProc", &((QDProcs *)theData)->textProc, bPointer, ProcessField, staticLink);
- FieldToString(" textProc", &((QDProcs *)theData)->textProc, bPointer, ProcessField, staticLink);
- FieldToString(" lineProc", &((QDProcs *)theData)->lineProc, bPointer, ProcessField, staticLink);
- FieldToString(" rectProc", &((QDProcs *)theData)->rectProc, bPointer, ProcessField, staticLink);
- FieldToString(" rRectProc", &((QDProcs *)theData)->rRectProc, bPointer, ProcessField, staticLink);
- FieldToString(" ovalProc", &((QDProcs *)theData)->ovalProc, bPointer, ProcessField, staticLink);
- FieldToString(" arcProc", &((QDProcs *)theData)->arcProc, bPointer, ProcessField, staticLink);
- FieldToString(" polyProc", &((QDProcs *)theData)->polyProc, bPointer, ProcessField, staticLink);
- FieldToString(" rgnProc", &((QDProcs *)theData)->rgnProc, bPointer, ProcessField, staticLink);
- FieldToString(" bitsProc", &((QDProcs *)theData)->bitsProc, bPointer, ProcessField, staticLink);
- FieldToString(" commentProc", &((QDProcs *)theData)->commentProc, bPointer, ProcessField, staticLink);
- FieldToString(" txMeasProc", &((QDProcs *)theData)->txMeasProc, bPointer, ProcessField, staticLink);
- FieldToString(" getPicProc", &((QDProcs *)theData)->getPicProc, bPointer, ProcessField, staticLink);
- FieldToString(" putPicProc", &((QDProcs *)theData)->putPicProc, bPointer, ProcessField, staticLink);
- break;
- }
-
- case bCQDProcs:
- {
- FieldToString(fieldLabel, NULL, bTitle, ProcessField, staticLink);
- FieldToString(" textProc", &((CQDProcs *)theData)->textProc, bPointer, ProcessField, staticLink);
- FieldToString(" lineProc", &((CQDProcs *)theData)->lineProc, bPointer, ProcessField, staticLink);
- FieldToString(" rectProc", &((CQDProcs *)theData)->rectProc, bPointer, ProcessField, staticLink);
- FieldToString(" rRectProc", &((CQDProcs *)theData)->rRectProc, bPointer, ProcessField, staticLink);
- FieldToString(" ovalProc", &((CQDProcs *)theData)->ovalProc, bPointer, ProcessField, staticLink);
- FieldToString(" arcProc", &((CQDProcs *)theData)->arcProc, bPointer, ProcessField, staticLink);
- FieldToString(" polyProc", &((CQDProcs *)theData)->polyProc, bPointer, ProcessField, staticLink);
- FieldToString(" rgnProc", &((CQDProcs *)theData)->rgnProc, bPointer, ProcessField, staticLink);
- FieldToString(" bitsProc", &((CQDProcs *)theData)->bitsProc, bPointer, ProcessField, staticLink);
- FieldToString(" commentProc", &((CQDProcs *)theData)->commentProc, bPointer, ProcessField, staticLink);
- FieldToString(" txMeasProc", &((CQDProcs *)theData)->txMeasProc, bPointer, ProcessField, staticLink);
- FieldToString(" getPicProc", &((CQDProcs *)theData)->getPicProc, bPointer, ProcessField, staticLink);
- FieldToString(" putPicProc", &((CQDProcs *)theData)->putPicProc, bPointer, ProcessField, staticLink);
- FieldToString(" opcodeProc", &((CQDProcs *)theData)->opcodeProc, bPointer, ProcessField, staticLink);
- FieldToString(" newProc1", &((CQDProcs *)theData)->newProc1, bPointer, ProcessField, staticLink);
- FieldToString(" newProc2", &((CQDProcs *)theData)->newProc2, bPointer, ProcessField, staticLink);
- FieldToString(" newProc3", &((CQDProcs *)theData)->newProc3, bPointer, ProcessField, staticLink);
- FieldToString(" newProc4", &((CQDProcs *)theData)->newProc4, bPointer, ProcessField, staticLink);
- FieldToString(" newProc5", &((CQDProcs *)theData)->newProc5, bPointer, ProcessField, staticLink);
- FieldToString(" newProc6", &((CQDProcs *)theData)->newProc6, bPointer, ProcessField, staticLink);
- break;
- }
-
- case bScrapStuff:
- DoScrapStuff(fieldLabel, (ScrapStuff *)theData, ProcessField, staticLink);
- break;
-
- case bConfigRec:
- DoConfigRecord(fieldLabel, (ConfigRecord *)theData, ProcessField, staticLink);
- break;
-
- case bSectionRecord:
- DoSectionRecord(fieldLabel, (SectionRecord *)theData, ProcessField, staticLink);
- break;
-
- default: // handle atomic datatypes
- switch (fieldType)
- {
- case bBoolean:
- {
- Str255 localString;
- NumberToHex(*((Ptr)theData), theString, 2);
- if (*((Boolean *)theData))
- localString = gBoolString[1];
- else
- localString = gBoolString[0];
- theString = localString + " (" + theString + ")";
- break;
- }
-
- case bFontName:
- GetFontName(*((IntegerPtr)theData), theString);
- break;
-
- case bInteger:
- NumToString(*((IntegerPtr)theData), theString);
- break;
-
- case bLongInt:
- NumToString(*((LongIntPtr)theData), theString);
- break;
-
- case bHexInteger:
- NumberToHex(*((IntegerPtr)theData), theString, 4);
- break;
-
- case bHexLongInt:
- NumberToHex(*((LongIntPtr)theData), theString, 8);
- break;
-
- case bHighByte:
- NumberToHex((*((IntegerPtr)theData) & 0xFF00) >> 8, theString, 2);
- break;
-
- case bLowByte:
- NumberToHex(*((IntegerPtr)theData) & 0x00FF, theString, 2);
- break;
-
- case bFixed:
- {
- NumToString(((*((LongIntPtr)theData)) & 0xFFFF0000) >> sizeof(short), aString);
- NumToString((short)((*((LongIntPtr)theData)) & 0x0000FFFF), theString);
- theString = aString + ":" + theString;
- break;
- }
-
- case bString:
- theString = *((Str255 *)theData);
- break;
-
- case bChar:
- {
- theString = " ";
- theString[1] = *((Ptr)theData);
- break;
- }
-
- case bGrafPtr:
- case bWindowPtr:
- case bPointer:
- {
- PointerToHex(*((LongIntPtr)theData), aString, 8);
- if ((*((LongIntPtr)theData) & 1) != 0)
- theString = "INVALID! (" + aString + ")";
- else if (*((HandlePtr)theData) == NULL)
- theString = "NULL";
- else
- theString = aString;
- break;
- }
-
- case bRgnHandle:
- case bControlHandle:
- case bTEHandle:
- case bHandle:
- {
- PointerToHex((long) * ((HandlePtr)theData), aString, 8);
- if ((*((LongIntPtr)theData) & 1) != 0)
- theString = "INVALID! (" + aString + ")";
- else if (*((HandlePtr)theData) == NULL)
- theString = "NULL";
- else
- theString = aString;
- break;
- }
-
- case bPoint:
- {
- NumToString((*((Point *)theData)).h, aString);
- NumToString((*((Point *)theData)).v, theString);
- theString = "(h:" + aString + ", v:" + theString + ")";
- break;
- }
-
- case bRect:
- {
- NumToString((*((Rect *)theData)).left, aString);
- NumToString((*((Rect *)theData)).top, theString);
- theString = "(l:" + aString + ", t:" + theString + ")/(r:";
- NumToString((*((Rect *)theData)).right, aString);
- theString = theString + aString + ", b:";
- NumToString((*((Rect *)theData)).bottom, aString);
- theString = theString + aString + ")";
- break;
- }
-
- case bObject:
- {
- PointerToHex((long) * ((HandlePtr)theData), aString, 8);
- if ((((long) * ((HandlePtr)theData)) & 1) != 0)
- theString = "INVALID! (" + aString + ")";
- else if (*((HandlePtr)theData) == NULL)
- theString = "NULL";
- else
- theString = aString;
- break;
- }
-
- case bByte:
- NumToString(*((Ptr)theData), theString);
- break;
-
- case bHLState:
- switch (*((HLState *)theData))
- {
- case 1:
- theString = "hlOff";
- break;
-
- case 2:
- theString = "hlDim";
- break;
-
- case 4:
- theString = "hlOn";
- break;
-
- default:
- NumToString(*((HLState *)theData), aString);
- theString = "INVALID! (" + aString + ")";
- break;
- }
- break;
-
- case bCmdNumber:
- NumToString(*((IntegerPtr)theData), theString);
- break;
-
- case bIDType:
- case bResType:
- case bOSType:
- {
- theString = "' '";
- for (short i = 1; i <= 4; i++)
- theString[i + 1] = *((char*)(((Ptr)theData) + i - 1));
- break;
- }
-
- case bPattern:
- {
- Str31 hexString;
- theString = "$";
- for (short i = 0; i <= 7; i++)
- {
- LIntToHex((*((Pattern *)theData))[i], hexString, 2);
- theString = theString + hexString;
- }
- break;
- }
-
- case bRGBColor:
- {
- if (((*((RGBColor *)theData)).red == 0) && ((*((RGBColor *)theData)).green == 0) && ((*((RGBColor *)theData)).blue == 0))
- theString = "Black";
- else if (((*((RGBColor *)theData)).red == 0xFFFF) && ((*((RGBColor *)theData)).green == 0xFFFF) && ((*((RGBColor *)theData)).blue == 0xFFFF))
- theString = "White";
- else
- {
- NumberToHex((*((RGBColor *)theData)).red, theString, 4);
- NumberToHex((*((RGBColor *)theData)).green, aString, 4);
- theString = theString + "/" + aString;
- NumberToHex((*((RGBColor *)theData)).blue, aString, 4);
- theString = theString + "/" + aString;
- }
- break;
- }
-
- case bStyle:
- {
- theString = "[";
- CheckStyleItem(bold, *((Style *)theData), theString, "bold");
- CheckStyleItem(italic, *((Style *)theData), theString, "italic");
- CheckStyleItem(underline, *((Style *)theData), theString, "underline");
- CheckStyleItem(outline, *((Style *)theData), theString, "outline");
- CheckStyleItem(shadow, *((Style *)theData), theString, "shadow");
- CheckStyleItem(condense, *((Style *)theData), theString, "condense");
- CheckStyleItem(extend, *((Style *)theData), theString, "extend");
- theString = theString + "]";
- break;
- }
-
- case bVCoordinate:
- NumToString(*((VCoordinate *)theData), theString);
- break;
-
- case bVPoint:
- {
- NumToString((*((VPoint *)theData)).h, aString);
- NumToString((*((VPoint *)theData)).v, theString);
- theString = "(h:" + aString + ", v:" + theString + ")";
- break;
- }
-
- case bVRect:
- {
- NumToString((*((VRect *)theData)).left, aString);
- NumToString((*((VRect *)theData)).top, theString);
- theString = "(l:" + aString + ", t:" + theString + ")/(r:";
- NumToString((*((VRect *)theData)).right, aString);
- theString = theString + aString + ", b:";
- NumToString((*((VRect *)theData)).bottom, aString);
- theString = theString + aString + ")";
- break;
- }
-
- case bStringHandle:
- {
- if (*((HandlePtr)theData) == NULL)
- theString = "NULL";
- else
- theString = ***((Str255 * **)theData);
- break;
- }
-
- case bCntlAdornment:
- {
- theString = "[";
- if (kFrame <= *((CntlAdornment *)theData))
- CheckAdornment(kFrame, *((CntlAdornment *)theData), theString, "frame");
- else
- {
- CheckAdornment(adnLineTop, *((CntlAdornment *)theData), theString, "top");
- CheckAdornment(adnLineLeft, *((CntlAdornment *)theData), theString, "left");
- CheckAdornment(adnLineBottom, *((CntlAdornment *)theData), theString, "bottom");
- CheckAdornment(adnLineRight, *((CntlAdornment *)theData), theString, "right");
- }
- // CheckAdornment(adnPatFill, *((CntlAdornment*) theData), theString, "fill");
- CheckAdornment(adnOval, *((CntlAdornment *)theData), theString, "oval");
- CheckAdornment(adnRRect, *((CntlAdornment *)theData), theString, "rrect");
- CheckAdornment(adnShadow, *((CntlAdornment *)theData), theString, "shadow");
- theString = theString + "]";
- break;
- }
-
- case bSizeDeterminer:
- switch (*((Ptr)theData)) // ¿¿¿
- {
- case 0:
- theString = "sizeSuperView";
- break;
-
- case 1:
- theString = "sizeRelSuperView";
- break;
-
- case 2:
- theString = "sizePage";
- break;
-
- case 3:
- theString = "sizeFillPages";
- break;
-
- case 4:
- theString = "sizeVariable";
- break;
-
- case 5:
- theString = "sizeFixed";
- break;
- }
- break;
-
- case bReal:
- case bSingle:
- {
- char destStr[80];
- sprintf(destStr, "%f", *((float*)theData));
- theString = destStr;
- break;
- }
-
- case bDouble:
- {
- char destStr[80];
- sprintf(destStr, "%f", *((double*)theData));
- theString = destStr;
- break;
- }
-
- case bExtended:
- {
- char destStr[80];
- sprintf(destStr, "%e", *((extended*)theData));
- theString = destStr;
- break;
- }
-
- case bVHSelect:
- switch (*((VHSelect *)theData))
- {
- case vSel:
- theString = "v";
- break;
-
- case hSel:
- theString = "h";
- break;
-
- default:
- NumToString((short) * ((VHSelect *)theData), aString);
- theString = "INVALID! (" + aString + ")";
- break;
- }
- break;
- } // switch for atomic types
-
- ProcessField(fieldLabel, theString, theData, fieldType, staticLink);
- } // switch for structured types
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
-
- typedef pascal void(* FieldToStringPtr)(const Str255& fieldLabel,
- void* theData,
- short fieldType,
- pascal void(* ProcessField)(const Str255& theLabel,
- const Str255& theString,
- void* theData,
- short theType,
- void* staticLink),
- void* staticLink);
- typedef pascal void(* FieldToCountPtr)(short& count,
- short fieldType);
-
- pascal void FieldToString(const Str255& fieldLabel,
- void* theData,
- short fieldType,
- pascal void(* ProcessField)(const Str255& theLabel,
- const Str255& theString,
- void* theData,
- short theType,
- void* staticLink),
- void* staticLink)
- {
- ((FieldToStringPtr)gFieldToStrRtn)(fieldLabel, theData, fieldType, ProcessField, staticLink);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
- pascal void FieldToCount(short& count,
- short fieldType)
- {
- ((FieldToCountPtr)gFieldToCountRtn)(count, fieldType);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAUtilitiesRes
- pascal long StripLong(void * address)
- {
- return ((long)address & (long)gStrippedAddress);
- }
-
-